package com.ruoyi.basedocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedocument.domain.BomSpecialmaterial;
import com.ruoyi.basedocument.service.IBomSpecialmaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM特殊物料Controller
 * 
 * @author ruoyi
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/bomcostestimation/basedocument/bomsm")
public class BomSpecialmaterialController extends BaseController
{
    @Autowired
    private IBomSpecialmaterialService bomSpecialmaterialService;

    /**
     * 查询BOM特殊物料列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomSpecialmaterial bomSpecialmaterial)
    {
        startPage();
        List<BomSpecialmaterial> list = bomSpecialmaterialService.selectBomSpecialmaterialList(bomSpecialmaterial);
        return getDataTable(list);
    }

    /**
     * 导出BOM特殊物料列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:export')")
    @Log(title = "BOM特殊物料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomSpecialmaterial bomSpecialmaterial)
    {
        List<BomSpecialmaterial> list = bomSpecialmaterialService.selectBomSpecialmaterialList(bomSpecialmaterial);
        ExcelUtil<BomSpecialmaterial> util = new ExcelUtil<BomSpecialmaterial>(BomSpecialmaterial.class);
        util.exportExcel(response, list, "BOM特殊物料数据");
    }

    /**
     * 获取BOM特殊物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bomSpecialmaterialService.selectBomSpecialmaterialById(id));
    }

    /**
     * 新增BOM特殊物料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:add')")
    @Log(title = "BOM特殊物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomSpecialmaterial bomSpecialmaterial)
    {
        return toAjax(bomSpecialmaterialService.insertBomSpecialmaterial(bomSpecialmaterial));
    }

    /**
     * 修改BOM特殊物料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:edit')")
    @Log(title = "BOM特殊物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomSpecialmaterial bomSpecialmaterial)
    {
        return toAjax(bomSpecialmaterialService.updateBomSpecialmaterial(bomSpecialmaterial));
    }

    /**
     * 删除BOM特殊物料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:bomsm:remove')")
    @Log(title = "BOM特殊物料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        int rows = bomSpecialmaterialService.deleteBomSpecialmaterialByIds(ids);
        return toAjax(rows+1);
    }

    /**
     * 批量查询物料
     */
	@GetMapping("/getNumbers/{numbers}")
    public TableDataInfo getListByNumber(@PathVariable String[] numbers)
    {
        List<BomSpecialmaterial> bomSpecialmaterials = bomSpecialmaterialService.selectBomSpecialmaterialListByNumber(numbers);
        return getDataTable(bomSpecialmaterials);
    }
}
